import 'package:flutter/material.dart';
import 'package:flutter_redux/flutter_redux.dart';
import 'package:redux/redux.dart';
import 'CountState.dart';

class ReduxTwo extends StatefulWidget {
  @override
  _ReduxTwoState createState() => _ReduxTwoState();
}

class _ReduxTwoState extends State<ReduxTwo> {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: Text("Redux测试子页"),
      ),
      floatingActionButton: StoreConnector<CountState, VoidCallback>(
          builder: (context, callback) {
        return FloatingActionButton(
          onPressed: callback,
          child: Icon(Icons.add),
        );
      }, converter: (store) {
        return () => store.dispatch(Action.increment);
      }),
      body: Center(
        child: StoreConnector<CountState, int>(
            builder: (context, count) {
              return Text(
                count.toString(),
                style: TextStyle(fontSize: 26, color: Colors.red[500]),
              );
            },
            converter: (store) => store.state.count),
      ),
    );
  }
}
